﻿namespace WenAntdUI.Helps;

/// <summary>
/// 消息提示窗
/// </summary>
public static class Msgbox
{
    /// <summary>
    /// 消息提示窗
    /// </summary>
    /// <param name="parent">父窗体</param>
    /// <param name="msg"></param>
    /// <param name="maskClosable">点击蒙层是否允许关闭</param>
    /// <returns></returns>
    public static DialogResult ShowInfo(this Form parent, string msg, bool maskClosable = true)
    {
        Form frm = parent;
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(frm, "提示", msg, AntdUI.TType.Info)
        {
            Font = frm.Font,
            MaskClosable = maskClosable,
            CancelText = null,
        });
        return res;
    }
    /// <summary>
    /// 消息提示窗
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="maskClosable"></param>
    /// <returns></returns>
    public static DialogResult ShowInfo(string msg, bool maskClosable = true)
    {
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(App.MainForm, "提示", msg, AntdUI.TType.Info)
        {
            MaskClosable = maskClosable,
            CancelText = null,
        });
        return res;
    }

    /// <summary>
    /// 成功提示窗
    /// </summary>
    /// <param name="parent">父窗体</param>
    /// <param name="msg"></param>
    /// <param name="maskClosable">点击蒙层是否允许关闭</param>
    /// <returns></returns>
    public static DialogResult ShowSuccess(this Form parent, string msg, bool maskClosable = true)
    {
        Form frm = parent;
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(frm, "成功", msg, AntdUI.TType.Success)
        {
            Font = frm.Font,
            MaskClosable = maskClosable,
            CancelText = null,
        });
        return res;
    }

    /// <summary>
    /// 成功提示窗
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="maskClosable"></param>
    /// <returns></returns>
    public static DialogResult ShowSuccess(string msg, bool maskClosable = true)
    {
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(App.MainForm, "成功", msg, AntdUI.TType.Success)
        {
            MaskClosable = maskClosable,
            CancelText = null,
        });
        return res;
    }

    /// <summary>
    /// 警告提示窗
    /// </summary>
    /// <param name="parent">父窗体</param>
    /// <param name="msg"></param>
    /// <param name="maskClosable">点击蒙层是否允许关闭</param>
    /// <returns></returns>
    public static DialogResult ShowWarn(this Form parent, string msg, bool maskClosable = true)
    {
        Form frm = parent;
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(frm, "警告", msg, AntdUI.TType.Warn)
        {
            Font = frm.Font,
            MaskClosable = maskClosable,
            CancelText = null,
        });
        return res;
    }
    /// <summary>
    /// 警告提示窗
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="maskClosable"></param>
    /// <returns></returns>
    public static DialogResult ShowWarn(string msg, bool maskClosable = true)
    {
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(App.MainForm, "警告", msg, AntdUI.TType.Warn)
        {
            MaskClosable = maskClosable,
            CancelText = null,
        });
        return res;
    }

    /// <summary>
    /// 错误提示窗
    /// </summary>
    /// <param name="parent">父窗体</param>
    /// <param name="msg"></param>
    /// <param name="maskClosable">点击蒙层是否允许关闭</param>
    /// <returns></returns>
    public static DialogResult ShowError(this Form parent, string msg, bool maskClosable = true)
    {
        Form frm = parent;
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(frm, "错误", msg, AntdUI.TType.Error)
        {
            Font = frm.Font,
            MaskClosable = maskClosable,
            CancelText = null,
        });
        return res;
    }

    /// <summary>
    /// 错误提示窗
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="maskClosable"></param>
    /// <returns></returns>
    public static DialogResult ShowError(string msg, bool maskClosable = true)
    {
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(App.MainForm, "错误", msg, AntdUI.TType.Error)
        {
            MaskClosable = maskClosable,
            CancelText = null,
        });
        return res;
    }

    /// <summary>
    /// 征询提示窗
    /// </summary>
    /// <param name="parent">父窗体</param>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static DialogResult ShowAsk(this Form parent, string msg)
    {
        Form frm = parent;
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(frm, "注意", msg, AntdUI.TType.Warn)
        {
            Font = frm.Font,
            MaskClosable = false,
        });
        return res;
    }

    /// <summary>
    /// 征询提示窗
    /// </summary>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static DialogResult ShowAsk(string msg)
    {
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(App.MainForm, "注意", msg, AntdUI.TType.Warn)
        {
            MaskClosable = false,
        });
        return res;
    }

    /// <summary>
    /// 弹出输入对话框
    /// </summary>
    /// <param name="parent"></param>
    /// <returns></returns>
    public static (bool Result, string Text) ShowInput(this Form parent, string title = "请输入")
    {
        var p = new Panel() { Dock = DockStyle.Fill, Width = 400 };

        var input = new AntdUI.Input()
        {
            Height = 50,
            Dock = DockStyle.Top,
        };

        var lable = new AntdUI.Label()
        {
            Height = 50,
            Dock = DockStyle.Top,
            Text = title
        };
        p.Controls.Add(input);
        p.Controls.Add(lable);

        Form frm = parent;
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(frm, "输入", p, AntdUI.TType.Warn)
        {
            Font = frm.Font,
            MaskClosable = false,
        });

        return (res == DialogResult.OK, input.Text);
    }

    public static (bool Result, string Text) ShowInput(string title = "请输入")
    {
        var p = new Panel() { Dock = DockStyle.Fill, Width = 400 };

        var input = new AntdUI.Input()
        {
            Height = 50,
            Dock = DockStyle.Top,
        };

        var lable = new AntdUI.Label()
        {
            Height = 50,
            Dock = DockStyle.Top,
            Text = title
        };
        p.Controls.Add(input);
        p.Controls.Add(lable);

        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(title, p, AntdUI.TType.Warn)
        {
            MaskClosable = false,
        });

        return (res == DialogResult.OK, input.Text);
    }

    public static bool ShowControl(Control control, string title = "提醒")
    {
        DialogResult res = AntdUI.Modal.open(new AntdUI.Modal.Config(title, control, AntdUI.TType.None)
        {
            MaskClosable = false,
            Btns = null,
            //BtnHeight = 0,
        });
        return res == DialogResult.OK;
    }

    /// <summary>
    /// 显示模型编辑窗体
    /// </summary>
    /// <param name="action"></param>
    /// <param name="title"></param>
    /// <returns></returns>
    public static bool ShowModelEdit(Action<Controls.ModelEdit> action, string title = "编辑")
    {
        var control = new Controls.ModelEdit()
        {
            Dock = DockStyle.Fill,
        };

        var fm = new WenForm
        {
            Text = title,
            Size = new Size(800, 600),
            StartPosition = FormStartPosition.CenterParent,
        };
        fm.Controls.Add(control);

        action?.Invoke(control);

        control.OkClick += (s, e) =>
        {
            fm.DialogResult = DialogResult.OK;
            fm.Close();
        };

        control.CancelClick += (s, e) =>
        {
            fm.DialogResult = DialogResult.Cancel;
            fm.Close();
        };

        return fm.ShowDialog() == DialogResult.OK;
    }
}